package com.mini.dubbo.consumer;

import static com.mini.dubbo.consumer.CustomBeanDefinitionRegistry.GOOD_BYE_SPRING_BEAN_NAME;
import static com.mini.dubbo.consumer.CustomBeanDefinitionRegistry.HELLO_SERVICE_SPRING_BEAN_NAME;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.mini.dubbo.api.IGoodbyeService;
import com.mini.dubbo.api.IHelloService;
import com.mini.dubbo.consumer.discovery.IServiceDiscovery;
import com.mini.dubbo.consumer.discovery.RedisServiceDiscovery;
import com.mini.dubbo.consumer.discovery.ZkServiceDiscovery;

/**
 * Created by yzy on 2018/11/3.
 */
public class Main {
    public static void main(String[] args){
       // IServiceDiscovery serviceDiscovery = new ZkServiceDiscovery();
        IServiceDiscovery serviceDiscovery = new RedisServiceDiscovery();
        RpcClientProxy rpcClientProxy = new RpcClientProxy(serviceDiscovery);


        IHelloService helloService = rpcClientProxy.create(IHelloService.class);
        IGoodbyeService goodbyeService = rpcClientProxy.create(IGoodbyeService.class);

        String resp = helloService.sayHello("习近平");
        System.out.println("helloService.sayHello 返回结果 "+resp);

        String resp2 = goodbyeService.sayByeBye("江泽民");
        System.out.println("goodbyeService.sayByeBye 返回结果"+resp2);


        //从spring 中获取
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class);

        IHelloService helloServiceBean = context.getBean(HELLO_SERVICE_SPRING_BEAN_NAME,IHelloService.class);
        String resp3 = helloServiceBean.sayHello("spring");
        System.out.println("helloService.sayHello for spring " + resp3);

        IGoodbyeService goodbyeServiceBean = context.getBean(GOOD_BYE_SPRING_BEAN_NAME, IGoodbyeService.class);
        String resp4 = goodbyeServiceBean.sayByeBye("dubbo");
        System.out.println(resp4);

    }
}
